

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>用户列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
  <div class="layui-card">

    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
      <ul class="layui-tab-title">
        <li class="layui-this" lay-id="1">事件列表</li>
        <li lay-id="2">疑似审核员</li>
      </ul>

      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">

          <blockquote class="layui-elem-quote">
            当App审核上架时，使用接口版本号添加审核事件，会将审核期间访问此接口版本号的App读者的<span style="color: #5FB878;">设备唯一标识</span>记录，并归属给疑似审核员列表，上架/推广后一定要关闭此审核事件！
          </blockquote>

          <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">App</label>
                <div class="layui-input-block">
                  <select name="quick_id" lay-search>
                    <option value="">请选择</option>
                    {foreach $qas as $k => $v}
                    <option value="{$v.id}">{$v.name}</option>
                    {/foreach}
                  </select>
                </div>
              </div>

              <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
                  <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
              </div>

            </div>
          </div>
          <div class="layui-card-body">
            <table id="LAY-user-back-role" lay-filter="LAY-user-back-role"></table>
            <script type="text/html" id="toolbarDemo">
              <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="add">添加事件</button>
              </div>
            </script>

            <script type="text/html" id="switchTpl">
              <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开|关" lay-filter="status" {{#  if(d.status == 1){ }}checked{{# }}}>
            </script>

            <script type="text/html" id="table-useradmin-admin">
              <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete" ></i></a>
            </script>
          </div>
        </div>
        <div class="layui-tab-item">
          <blockquote class="layui-elem-quote">
            此列表内读者只能看到审核内容，同一设备标识会有多个读者，只要有一个被屏蔽，则此设备的所有读者都被屏蔽
          </blockquote>

          <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label" style="white-space:nowrap!important;">设备唯一标识</label>
                <div class="layui-input-block">
                  <input type="text" name="userId" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
              </div>

              <div class="layui-inline">
                <label class="layui-form-label">来源事件ID</label>
                <div class="layui-input-block">
                  <input type="number" name="event_id" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
              </div>

              <div class="layui-inline">
                <label class="layui-form-label">App</label>
                <div class="layui-input-block">
                  <select name="quick_id" lay-search>
                    <option value="">请选择</option>
                    {foreach $qas as $k => $v}
                    <option value="{$v.id}">{$v.name}</option>
                    {/foreach}
                  </select>
                </div>
              </div>

              <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-search">
                  <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
              </div>

            </div>
          </div>
          <div class="layui-card-body">
            <table id="LAY-user" lay-filter="LAY-user-back-role"></table>
            <script type="text/html" id="switchStatusTpl">
              <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="屏蔽|忽略" lay-filter="userStatus" {{#  if(d.status == 1){ }}checked{{# }}}>
            </script>
          </div>



        </div>
      </div>
    </div>

  </div>
</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
  layui.config({
    base: '/static/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index','table','admin','element'], function(){
    var $ = layui.$
            ,form = layui.form
            ,admin = layui.admin
            ,table = layui.table;
    var element = layui.element;

    //获取hash来切换选项卡，假设当前地址的hash为lay-id对应的值
    var layid = location.hash.replace(/^#docDemoTabBrief=/, '');
    element.tabChange('docDemoTabBrief', layid); //假设当前地址为：http://a.com#test1=222，那么选项卡会自动切换到“发送消息”这一项

    //监听Tab切换，以改变地址hash值
    element.on('tab(docDemoTabBrief)', function(){
      location.hash = 'docDemoTabBrief='+ this.getAttribute('lay-id');
    });

    //监听搜索
    form.on('submit(LAY-user-back-search)', function(data){
      var field = data.field;

      //执行重载
      table.reload('LAY-user-back-role', {
        where: field
        ,page: {
          curr: 1  // 将页码重置为第一页
        }
      });
    });
    form.on('submit(LAY-user-search)', function(data){
      var field = data.field;

      //执行重载
      table.reload('LAY-user', {
        where: field
        ,page: {
          curr: 1  // 将页码重置为第一页
        }
      });
    });
    //监听开关
    form.on('switch(status)', function(data){
      if (data.elem.checked == true) {
        var value = 1;
        var title = "确认打开事件开关吗？";
      } else {
        var value = 0;
        var title = "确认关闭事件开关吗？";
      }
      layer.confirm(title, {icon: 3, title: false}, function (index) {
        admin.req({
          url: '/quick_app/editAuditEventField'
          , type: "POST"
          , data: {'id': data.value, 'field': 'status', 'value': value}
          , done: function (res) {
            layer.msg('设置成功', {icon: 1, time: 1000}, function () {
            });
          }, not_finish: function (res) {
            layer.msg(res.msg,function () {
              table.reload('LAY-user-back-role');
            });
          }
        });
      }, function(index){
        table.reload('LAY-user-back-role');
      });
    });


    form.on('switch(userStatus)', function(data){
      if (data.elem.checked == true) {
        var value = 1;
        var title = "确认屏蔽此用户吗？";
      } else {
        var value = 0;
        var title = "确认忽略此用户吗？";
      }
      layer.confirm(title, {icon: 3, title: false}, function (index) {
        admin.req({
          url: '/quick_app/setAuditorStatus'
          , type: "POST"
          , data: {'id': data.value, 'status': value}
          , done: function (res) {
            layer.msg('设置成功', {icon: 1, time: 1000}, function () {
            });
          }, not_finish: function (res) {
            layer.msg(res.msg,function () {
              table.reload('LAY-user');
            });
          }
        });
      }, function(index){
        table.reload('LAY-user');
      });
    });

    table.render({
      elem: '#LAY-user-back-role'
      , url: '/quick_app/auditEventList' //模拟接口
      , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
      , defaultToolbar: false
      , cellMinWidth: 100
      , response: {
        statusCode: 1 //规定成功的状态码，本来是：0，现在统一改为1
      }
      , page: true //开启分页
      , cols: [
        [{field: 'id', width: 80, title: 'ID'}
          ,{field:'status', title:'开关', width:85, templet: '#switchTpl', unresize: true, align: 'center'}
          , {field: 'quick_app', title: 'App',templet:function (d) {
              return d.quick_app.name;
          }, width:150,align: 'center'}
          , {field: 'api_version', title: '<span lay-tips="开关打开后记录请求此接口版本号的用户">接口版本号</span>', minWidth: 120, align: 'center'}

          , {field: 'desc', title: '备注', edit: 'text',minWidth:100}
          , {
          title: '操作',
          width: 100,
          align: 'center',
          fixed: 'right',
          toolbar: '#table-useradmin-admin',
        }]]
    });

    table.render({
      elem: '#LAY-user'
      , url: '/quick_app/auditorList' //模拟接口
      , cellMinWidth: 100
      , response: {
        statusCode: 1 //规定成功的状态码，本来是：0，现在统一改为1
      }
      , page: true //开启分页
      , cols: [
        [
          {field: 'id', width: 80, title: 'ID', rowspan: 2}
          , {field: 'status', title: '状态', width: 100, templet: '#switchStatusTpl', unresize: true, align: 'center', rowspan: 2}
          , {field: 'userId', title: '设备唯一标识', minWidth: 550,rowspan:2}
          , {field: 'ip', title: 'ip', minWidth: 100,rowspan:2}
          , {align: 'center', title: '来源', colspan: 4}
          , {field: 'create_time', title: '添加时间', rowspan: 4}
        ], [
          {field: 'event_id', title: '事件Id', width: 100, align: 'center', minWidth: 150}
          ,{
            field: 'quick_app', title: 'App', width: 150, align: 'center', templet: function (d) {
              return d.quick_app.name;
            }
          }
          , {field: 'api_version', title: '接口版本号', width: 100, align: 'center', minWidth: 150}

        ]]
    });


    //监听单元格编辑
    table.on('edit(LAY-user-back-role)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
      console.log(obj.value); //得到修改后的值
      console.log(obj.field); //当前编辑的字段名
      admin.req({
        url: '/quick_app/editAuditEventField'
        , type: "POST"
        , data: {'id': obj.data.id, 'field': obj.field, 'value': obj.value}
        , done: function (res) {
          layer.msg('修改成功', {icon: 1, time: 1000}, function () {
          });
        }, not_finish: function (res) {
          layer.msg(res.msg);
        }
      });
    });


    //头工具栏事件
    table.on('toolbar(LAY-user-back-role)', function (obj) {
      var checkStatus = table.checkStatus(obj.config.id);
      switch (obj.event) {
        case 'add':
          layer.open({
            type: 2
            ,maxmin: true//开启最大化最小化按钮
            ,title: '添加审核事件'
            ,content: '/quick_app/addAuditEvent'
            ,offset: '5px'
            ,area: ['500px', '420px']
            ,btn: ['确定', '取消']
            ,yes: function(index, layero){
              var iframeWindow = window['layui-layer-iframe'+ index]
                      ,submit = layero.find('iframe').contents().find("#LAY-user-role-submit");

              //监听提交
              iframeWindow.layui.form.on('submit(LAY-user-role-submit)', function(data){
                var field = data.field; //获取提交的字段
                //提交 Ajax 成功后，静态更新表格中的数据
                //$.ajax({});
                admin.req({
                  url: '/quick_app/addAuditEvent'
                  , type: "POST"
                  , data: field
                  , done: function (res) {
                    layer.msg('添加成功', {icon: 1, time: 2000}, function () {
                      table.reload('LAY-user-back-role');
                      layer.close(index); //关闭弹层
                    });
                  },not_finish:function (res) {
                    layer.msg(res.msg);
                  }
                });
              });

              submit.trigger('click');
            }
          });
          break;
      }
    });



    //监听工具条
    table.on('tool(LAY-user-back-role)', function(obj){
      var data = obj.data;
      if (obj.event === 'del'){
        layer.confirm('确认删除审核事件'+obj.data.id, {icon: 3, title:false}, function(index){
          admin.req({
            url: '/quick_app/delAuditEvent'
            , type: "POST"
            , data: {'id': obj.data.id}
            , done: function (res) {
              layer.msg('删除成功', {icon: 1, time: 1000}, function () {
                obj.del();
                layer.close(index);
              });
            },not_finish:function (res) {
              layer.msg(res.msg);
            }
          });
        });
      }
    });
  });
</script>
</body>
</html>

